package com.lxx.wiki.controller;

import com.lxx.wiki.domain.req.CategorySaveReq;
import com.lxx.wiki.domain.req.DocSaveReq;
import com.lxx.wiki.domain.resp.CategoryQueryResp;
import com.lxx.wiki.domain.resp.CommonResp;
import com.lxx.wiki.domain.resp.DocQueryResp;
import com.lxx.wiki.service.CategoryService;
import com.lxx.wiki.service.DocService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/doc")
public class DocController {

    @Autowired
    private DocService docService;

    /**
     * 查询全部
     * @return
     */
    @GetMapping("/all")
    public CommonResp all(Long ebookId) {
        List<DocQueryResp> docQueryRespList = docService.all(ebookId);

        CommonResp<List<DocQueryResp>> resp = new CommonResp<>();
        resp.setContent(docQueryRespList);

        return resp;
    }

    /**
     * 新增或修改
     */
    @PostMapping("/save")
    public CommonResp save(@Valid @RequestBody DocSaveReq docSaveReq) {
        docService.save(docSaveReq);
        return new CommonResp<>();
    }

    /**
     * 根据id删除
     */
    @DeleteMapping("/del/{ids}")
    public CommonResp del(@PathVariable String ids) {
        docService.del(ids);
        return new CommonResp<>();
    }

}
